from flask import Flask,url_for,redirect,abort,render_template,request

app  = Flask(__name__)

@app.route('/')
def index():
    r1 = url_for('hello')
    r2 = url_for('uname',username='lisi')
    # print(r2)
    # print(r1)

    # 重定向 redirect
    # return redirect(r2)

    # 获取参数 arguments
    # print(request.args.get('a',None))
    # 获取所有GET请求数据,转为字典
    print(request.args.to_dict())

    return 'index,你好'

    # 错误
    # abort(404)


@app.route('/hello',methods=['POST','GET'])
def hello():    
    return 'hello'

@app.route('/name/<username>')
def uname(username):
    return 'hello'+username

@app.route('/list/<int:page>')
def user(page):
    print(page)
    return 'yema跳转'


# 抛出404
# @app.errorhandler(404)
# def page_not_found(error):
#     return render_template('404.html'),404

if __name__ == '__main__':
    app.run(host='0.0.0.0',debug=True)